﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using syc.Helper;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;

namespace syc.Sale
{
    public partial class Report_CaiGou_Day : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            DateTime date1 = DateTime.Parse(Request.QueryString["Date1"]);//月初日期
            DateTime date3 =DateTime.Parse(Request.QueryString["Date3"]);//生成报表日期
            this.SqlDataSource1.SelectCommand = @"select 主材名称,单位,名称,sum(当日到货量)as 当日到货量,到货日期,dbo.当月累计(主材名称,名称,到货日期,'" + date1 + "') as 当月累计量,dbo.当月合同量(主材名称,名称,到货日期,'" + date1 + "') as 当月合同量,dbo.当年累计(主材名称,名称,到货日期) as 当年累计量 from 主要原材料到货日记录 where 到货日期='" + date3 + "'group by 主材名称,名称,单位,到货日期,dbo.当月累计(主材名称,名称,到货日期,'" + date1 + "'),dbo.当月合同量(主材名称,名称,到货日期,'" + date1 + "'),dbo.当年累计(主材名称,名称,到货日期)";
            this.ViewState["SelectCommand"] = this.SqlDataSource1.SelectCommand;

            GridViewHelper helper = new GridViewHelper(this.GridView1);
            string[] cols = new string[2];
            cols[0] = "主材名称";
            cols[1] = "单位";

            helper.RegisterGroup(cols, true, true);
            helper.RegisterSummary("当日到货量", SummaryOperation.Sum, "主材名称+单位");
            helper.RegisterSummary("当月累计量", SummaryOperation.Sum, "主材名称+单位");
            helper.RegisterSummary("当月合同量", SummaryOperation.Sum, "主材名称+单位");
            helper.RegisterSummary("当年累计量", SummaryOperation.Sum, "主材名称+单位"); 
            helper.GroupSummary += new GroupEvent(helper_GroupSummary);
            helper.ApplyGroupSort();  
        


        }
        private void helper_GroupSummary(string groupName, object[] values, GridViewRow row)
        {
            row.Cells[0].HorizontalAlign = HorizontalAlign.Right;
            row.Cells[0].Text = "小计";           
        }
    }
}
